import 'dart:io';
import 'dart:typed_data';

import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';



typedef OnChangeFileCallback = void Function(XFile payload);

class PickerImageButton extends StatefulWidget {
  const PickerImageButton({super.key, this.onChange});
  final OnChangeFileCallback? onChange;
  @override
  State<PickerImageButton> createState() => _PickerImageButtonState();
}

class _PickerImageButtonState extends State<PickerImageButton>{

  File? _image;
  onPaste(BuildContext context){
    _pickImageFromGallery();
  }

  _pickImageFromGallery() async {
    final picker = ImagePicker();
    final pickedFile = await picker.pickImage(source: ImageSource.gallery);
    if(pickedFile!=null){

      widget.onChange!(pickedFile);
    }
  }

  @override
  Widget build(BuildContext context) {
    return IconButton(onPressed: ()=>onPaste(context), icon: const Icon(Icons.image_search_outlined));
  }
}
